<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/5.15.1/css/all.min.css" rel="stylesheet">
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        body {
            display: flex;
            height: 100vh;
            justify-content: center;
            align-items: center;
            background: #e67e22;
        }

        .search-box {
            height: 40px;
            background: #2c3e50;
            padding: 10px;
            display: flex;
            justify-content: space-between;
            align-items: center;
            border-radius: 40px;
        }

        .search-box .search-btn {
            display: flex;
            width: 40px;
            height: 40px;
            border-radius: 40px;
            align-items: center;
            justify-content: center;
            text-decoration: none;
            font-size: 20px;
            color: #e67e22;
        }

        .search-box .search-input {
            background: none;
            border: none;
            outline: none;
            font-size: 20px;
            color: #fff;
            width: 0;
            transition: .5s;
        }

        .search-box:hover .search-input {
            width: 250px;
            padding-left: 10px;
        }

        .search-input:focus {
            width: 250px;
            padding-left: 10px;
        }
    </style>
</head>

<body>
    <div class="search-box">
        <input type="text" class="search-input">
        <a href="" class="search-btn">
            <i class="fas fa-search"></i>
        </a>
    </div>
</body>
<script>
    var search_input = document.querySelector('.search-input');
    search_input.onchange = function () {
        // console.log(search_input.value);
        this.style.caretColor = '#fff';
        if (search_input.value != '') {
            this.style.width = 250 + 'px';
            this.style.paddingLeft = 10 + 'px';
        } else {
            search_input.style.width = 0;
        }
    }
    search_input.onblur = function () {
        this.style.caretColor = 'transparent';
    }
</script>

</html>